<html>
<head><meta charset="utf-8"><title>devkita64 tls help · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/devkita64.20tls.20help.html">devkita64 tls help</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="204419034"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/devkita64%20tls%20help/near/204419034" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> leo60228 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/devkita64.20tls.20help.html#204419034">(Jul 20 2020 at 13:03)</a>:</h4>
<p>I'm working on a Rust target for DevkitA64 (the most popular toolchain for Nintendo Switch homebrew). DevkitA64, for historical reasons, uses soft TLS instead of hard TLS. Soft TLS is <em>very</em> uncommon on aarch64, and upstream LLVM doesn't support it. There's a patch adding it at <a href="https://github.com/Thog/llvm/commit/8657ba2a3b1c8433259e68040b5724f0b8118a09">https://github.com/Thog/llvm/commit/8657ba2a3b1c8433259e68040b5724f0b8118a09</a>, but it seems too specific to upstream, but also doesn't make much sense to add to Rust's LLVM fork...</p>



<a name="204419667"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/devkita64%20tls%20help/near/204419667" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/devkita64.20tls.20help.html#204419667">(Jul 20 2020 at 13:09)</a>:</h4>
<p>Can you implement it in libstd instead? <code>#[thread_local] static</code> is nightly only, so pretty much everyone uses the <code>thread_local!</code> macro, which can expand to whatever code you want to implement TLS.</p>



<a name="204420785"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/devkita64%20tls%20help/near/204420785" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> leo60228 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/devkita64.20tls.20help.html#204420785">(Jul 20 2020 at 13:19)</a>:</h4>
<p>I'm not sure. I don't <em>think</em> so, but maybe? I've asked the author of that patch.</p>



<a name="204422527"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/devkita64%20tls%20help/near/204422527" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> leo60228 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/devkita64.20tls.20help.html#204422527">(Jul 20 2020 at 13:36)</a>:</h4>
<p>Non-ELF TLS works fine because the actual TLS code is compiled by GCC. I'm going to try and get ELF TLS working anyway, just because I feel like not doing that could lead to issues with stuff like errno later on.</p>



<a name="204427344"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/devkita64%20tls%20help/near/204427344" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> leo60228 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/devkita64.20tls.20help.html#204427344">(Jul 20 2020 at 14:17)</a>:</h4>
<p>Just got that patch working, for what it's worth.</p>



<a name="204445241"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/devkita64%20tls%20help/near/204445241" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/devkita64.20tls.20help.html#204445241">(Jul 20 2020 at 16:38)</a>:</h4>
<p><span class="user-mention" data-user-id="239001">@leo60228</span> I think what <span class="user-mention" data-user-id="133247">@bjorn3</span> is referring to uses the <code>pthread_key_create</code> / <code>pthread_{set,get}specific</code> API, so if you have something like that you should be able to integrate it</p>



<a name="204445286"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/devkita64%20tls%20help/near/204445286" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> leo60228 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/devkita64.20tls.20help.html#204445286">(Jul 20 2020 at 16:38)</a>:</h4>
<p>I know, that works. I'm just worried about what happens when Rust tries to access TLS defined in C code.</p>



<a name="204445305"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/devkita64%20tls%20help/near/204445305" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/devkita64.20tls.20help.html#204445305">(Jul 20 2020 at 16:38)</a>:</h4>
<p>I'm not even sure we use LLVM soft TLS anywhere. maybe we should, to make <code>#[thread_local]</code> work everywhere</p>



<a name="204445314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/devkita64%20tls%20help/near/204445314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/devkita64.20tls.20help.html#204445314">(Jul 20 2020 at 16:39)</a>:</h4>
<p>ah, for like <code>errno</code>?</p>



<a name="204445328"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/devkita64%20tls%20help/near/204445328" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> leo60228 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/devkita64.20tls.20help.html#204445328">(Jul 20 2020 at 16:39)</a>:</h4>
<p>Yeah.</p>



<a name="204445336"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/devkita64%20tls%20help/near/204445336" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/devkita64.20tls.20help.html#204445336">(Jul 20 2020 at 16:39)</a>:</h4>
<p>you can pretty much ensure it never happens, I think?</p>



<a name="204445456"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/devkita64%20tls%20help/near/204445456" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/devkita64.20tls.20help.html#204445456">(Jul 20 2020 at 16:40)</a>:</h4>
<p>there's a <code>has_elf_tls</code> flag in the target spec that controls whether <code>#[thread_local]</code> even exists</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>